package com.manage.service;

import java.util.List;

import org.apache.log4j.Logger;

import com.manage.config.Config;
import com.manage.model.SpCodeConfirm;
//import com.manage.model.vo.VSpCodeConfirm;
import com.service.AbstractService;
import com.util.ConfigUtil;
import com.utils.dbcp.ConnectionManager;
import com.utils.dbcp.ModelGenerator;

public class SpCodeConfirmServiceImpl extends AbstractService implements SpCodeConfirmService{
	private Logger logger;
	public SpCodeConfirmServiceImpl()
	{
		logger = Logger.getLogger(this.getClass());
		this.dbcp = ConfigUtil.get(Config.SECTION, Config.KEY_DBCP_NAME);
	}
	@Override
	public SpCodeConfirm getSpCodeConfirmById(int id) {
		String sql = "select * from spcodeconfirm where id="+id;
		ModelGenerator<SpCodeConfirm> dbcpmg = new ModelGenerator<SpCodeConfirm>(SpCodeConfirm.class);
		return dbcpmg.generate(dbcp, sql);
	}

	@Override
	public List<SpCodeConfirm> getSpCodeConfirmsBySpCodeId(int spCodeId) {
		String sql = "select * from spcodeconfirm where spcodeid="+spCodeId+" order by createdate desc";
		ModelGenerator<SpCodeConfirm> dbcpmg = new ModelGenerator<SpCodeConfirm>(SpCodeConfirm.class);
		return dbcpmg.generateList(dbcp, sql);
	}
//	private int confirmType;
//	private String issuedPort;
//	private String issuedKey;
//	private String isFilter;
	@Override
	public boolean saveSpCodeConfirm(SpCodeConfirm spCodeConfirm, String type) {
		String sql ="";
		if(type.equalsIgnoreCase("insert"))
		{
			spCodeConfirm.setId(getTableId("spcodeconfirm"));
			sql = "insert into spcodeconfirm(id,spcodeid,confirmType,issuedPort,issuedKey,isFilter,confirmCodeType,confirmCodeContent1" +
					",confirmCodeContent2,confirmCmdType,confirmCmdContent1" +
					",confirmCmdContent2,createuser,createdate,confirmprovince) values (" +
					""+spCodeConfirm.getId()+",'"+spCodeConfirm.getSpCodeId()+
					"','"+spCodeConfirm.getConfirmType()+"','"+spCodeConfirm.getIssuedPort()+"','"+spCodeConfirm.getIssuedKey()+"','"+spCodeConfirm.getIsFilter()+
					"','"+spCodeConfirm.getConfirmCodeType()+"','"+spCodeConfirm.getConfirmCodeContent1()+
					"','"+spCodeConfirm.getConfirmCodeContent2()+
					"','"+spCodeConfirm.getConfirmCmdType()+"','"+spCodeConfirm.getConfirmCmdContent1()+
					"','"+spCodeConfirm.getConfirmCmdContent2()+
					"','"+spCodeConfirm.getCreateUser()+
					"','"+spCodeConfirm.getCreateDate()+"','"+spCodeConfirm.getConfirmProvince()+"')";
		}else if (type.equalsIgnoreCase("update"))
		{
			sql="update spcodeconfirm set confirmType='"+spCodeConfirm.getConfirmType()+"',issuedPort='"+spCodeConfirm.getIssuedPort()+"'" +
					",issuedKey='"+spCodeConfirm.getIssuedKey()+"',isFilter='"+spCodeConfirm.getIsFilter()+"'," +
					"confirmCodeType='"+spCodeConfirm.getConfirmCodeType()+
				"',confirmCodeContent1='"+spCodeConfirm.getConfirmCodeContent1()+
				"',confirmCodeContent2='"+spCodeConfirm.getConfirmCodeContent2()+
				"',confirmCmdType='"+spCodeConfirm.getConfirmCmdType()+
				"',confirmCmdContent1='"+spCodeConfirm.getConfirmCmdContent1()+
				"',confirmCmdContent2='"+spCodeConfirm.getConfirmCmdContent2()+
				"',confirmprovince='"+spCodeConfirm.getConfirmProvince()+"' where " +
					"id ="+spCodeConfirm.getId();
		}
		else if (type.equalsIgnoreCase("delete"))
		{
			sql="delete from spcodeconfirm where " +
			"id ="+spCodeConfirm.getId();
		}
		return ConnectionManager.getInstance().execute(dbcp, sql);
	}
//	@Override
//	public List<VSpCodeConfirm> getSpCodeConfirms() {
//		String sql = "select * from spcodeconfirm order by createdate desc";
//		ModelGenerator<VSpCodeConfirm> dbcpmg = new ModelGenerator<VSpCodeConfirm>(VSpCodeConfirm.class);
//		return dbcpmg.generateList(dbcp, sql);
//	}

}
